<?php
	if ( sizeof($_POST) > 0 )
	{
		$eeRO_data = array('userid' => $_POST['userid'], 'user_pass' => $_POST['user_pass']);
		$eeRO_error = array();
		
		if ( !preg_match('/^[0-9a-z_]{4,23}$/i', $eeRO_data['userid']) )
		{
			$eeRO_error['userid'] = true;
		}
		
		if ( !preg_match('/^[0-9a-z_]{4,32}$/i', $eeRO_data['user_pass']) )
		{
			$eeRO_error['user_pass'] = true;
		}
		
		if ( sizeof($eeRO_error) > 0 )
		{
			$eeRO_view->assign('error', $eeRO_error);
			$eeRO_view->assign('module', array('title' => 'Вход', 'template' => 'account_login.html'));
		}
		else
		{
			$eeRO_data['password'] = ( $eeRO_config->options['md5'] ) ? md5($eeRO_data['user_pass']) : $eeRO_data['user_pass'];
			$eeRO_base_ragnarok->query('SELECT `account_id`, `userid`, `email`, `sex`, `level` AS `user_level` FROM `login` WHERE `userid`=:userid AND `user_pass`=:user_pass', array(':userid' => $eeRO_data['userid'], ':user_pass' => $eeRO_data['password']));
			if ( $eeRO_base_ragnarok->num() > 0 )
			{
				$eeRO_user = $eeRO_base_ragnarok->fetch();
				$eeRO_session->set('eeRO_user', $eeRO_user);
				$eeRO_view->assign('module', array('title' => 'Вход', 'template' => 'account_login_yes.html'));
				
			}
			else
			{
				$eeRO_view->assign('error', array('userid_error' => true));
				$eeRO_view->assign('module', array('title' => 'Вход', 'template' => 'account_login.html'));
			}
		}
	}
	else
	{
		$eeRO_view->assign('module', array('title' => 'Вход', 'template' => 'account_login.html')); 
	}